loadmod("class")
local modname="action"
module(modname,package.seeall)
function new (modname)
	_G[modname] = _G[modname] or {}
	o=_G[modname]
	package.loaded[modname] =o 
	setfenv(2, o)
	class.bindclass(o,action)
	local t=getmetatable(o) or {}
	t.__call=o.start
	t.__index=_G
	setmetatable(o,t)
	o.init()
	return o
end

class.defclassfunc()
init=function(self)
	self.argdata={}
	self._bindedtris={}
	self.setargs()
end

newarg=function(self,argname,comment,argdefval)
	if self.argdata==nil then self.argdata={} end
	self.argdata[argname]=argdefval
end


setargs=function(self,args)
	self.args=args or {}
	tablefunc.gmt(self.args).__index=self.argdata
end

bindtri=function(self,triname)
	self._bindedtris[triname]=true
end

start=function(self,args)
	self.setargs(args)
	if self.__start__ then self.__start__() end
	local i,v
	for i,v in pairs(self._bindedtris) do
		loadtri(i)
	end
end

act=function(self,flag)
	self.flag=flag or self.flag
	if self.flag==nil then
		self.stop()
	elseif self[self.flag] then
		self[self.flag]()
		self.resumeing=false
	else
		self.stop()
	end
end

resume=function(self)
	self.resumeing=true
	self.act()
end
stop=function(self,endstatus,...)
	local i,v
	for i,v in pairs(self._bindedtris) do
		unloadtri(i)
	end
	if self.__stop__ then self.__stop__(endstatus) end
	if endstatus then
		if self.args[endstatus] then self.args[endstatus]() end
	end
end